In [14]:
edges =[]
for line in open('facebook_combined.txt'):
if line[0] != '#':
# print(line.replace('\n','').split(' ')) # \n es salto de linea, .split(' ') -> separar por espacio, .split('\t') -> si esta separado por tabulación
d = line.replace('\n','').split(' ')
edges.append((d[0],d[1]))
#print(edges)
In [34]:
import networkx as nx
G = nx.Graph() # G = nx.Graph(edges), otro modo de crear el grafo
G.add_edges_from(edges)
degrees = [degree for _, degree in G.degree().items()]
In [35]:
G_rand = nx.Graph()
N = len(G.nodes())
p = 2*len(edges)/(N*(N-1))
G_rand = nx.gnp_random_graph(N,p)
#print(d)
In [38]:
import seaborn as sns
sns.set()
%matplotlib inline
ax = sns.distplot(list(G.degree().values()))
sns.distplot(list(G_rand.degree().values()))
#ax.set(xscale="log", yscale="log")
Out[38]:
In [ ]:
In [ ]: